package com.ruoyi.exam.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.exam.task.DailyTaskPaperGenerator;

@RestController
@RequestMapping("/exam/daily")
public class DailyTaskController extends BaseController {

    @Autowired
    private DailyTaskPaperGenerator dailyTaskPaperGenerator;

    /**
     * 手动触发生成每日一练试卷
     */
    @GetMapping("/generate/{taskId}")
    @Anonymous
    public AjaxResult generateDailyPaper(@PathVariable(required = false) Long taskId) {
        try {
            dailyTaskPaperGenerator.generateDailyTaskPaperManually(taskId);
            return AjaxResult.success("生成成功");
        } catch (Exception e) {
            return AjaxResult.error("生成失败：" + e.getMessage());
        }
    }

    /**
     * 手动触发生成所有每日一练试卷
     */
    @GetMapping("/generate")
    @Anonymous
    public AjaxResult generateAllDailyPapers() {
        try {
            dailyTaskPaperGenerator.generateDailyTaskPaperManually(null);
            return AjaxResult.success("生成成功");
        } catch (Exception e) {
            return AjaxResult.error("生成失败：" + e.getMessage());
        }
    }
}